﻿@{
    ViewBag.Title = "管理登录 - 后台管理系统";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header{
    <link href='/yisha/css/login.css' rel="stylesheet" />
    <script src="/lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <style>
        .login-left {
            position: absolute;
            margin-top: 200px;
            margin-left: 200px;
        }

            .login-left p {
                margin-top: -10px;
                text-align: left;
                color: #808080;
                font-size: 16px;
                line-height: 30px;
            }

        .login-left-bg {
            background: url(/images/login-left-bg.png) left no-repeat;
            width: 765px;
            height: 500px;
            margin-top: 20px;
        }

        .ui.horizontal.session-login__oauth-title {
            font-weight: normal;
        }
        .ui.horizontal.divider {
            display: table;
            white-space: nowrap;
            height: auto;
            margin: '';
            line-height: 1;
            text-align: center;
        }
        .ui.divider {
            margin: 1rem 0rem;
            line-height: 1;
            height: 0em;
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: rgba(0,0,0,0.85);
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            -webkit-tap-highlight-color: rgba(0,0,0,0);
        }
        .ui.horizontal.divider:before, .ui.horizontal.divider:after {
            background-image: url();
        }
        .ui.horizontal.divider:before {
            background-position: right 1em top 50%;
        }
        .ui.horizontal.divider:after {
            background-position: left 1em top 50%;
        }
        .ui.horizontal.divider:before, .ui.horizontal.divider:after {
            content: '';
            display: table-cell;
            position: relative;
            top: 50%;
            width: 50%;
            background-repeat: no-repeat;
        }
        .layui-form-item.login-oauth-group > a  {
            margin:10px;
        }
       .layui-form-item.login-oauth-group > a > .layui-icon {
            font-size: 26px;
        }
    </style>
}
<div class="login-left">
    <p style="width:550px;text-align:left;">GeneralNetCore是一套快速开发的后端框架，此系统为《理工邦》平台，主要是帮助理工人士找工作、找朋友及找恋人。</p>
    <div class="login-left-bg"></div>
</div>

<div class="login-panel">
    <div class="row section">
        <div class="col-sm-12">
            <form id="form">
                <p style="text-align: center;margin-bottom: 30px;font-size: 20px;">用户登录</p>
                <input id="userName" name="userName" class="form-control uname" col="UserName" type="text" placeholder="登录账号" value="" />
                <input id="password" name="password" class="form-control pword m-b" col="Password" type="password" placeholder="登录密码" value="" />
                <div class="row">
                    <div class="col-xs-6">
                        <input id="captchaCode" name="captchaCode" type="text" col="CaptchaCode" class="form-control code" placeholder="验证码" maxlength="3">
                    </div>
                    <div class="col-xs-6" style="text-align:right">
                        <a href="javascript:void(0);" title="点击更换验证码">
                            <img id="imgCaptchaCode" src='@Url.Content("~/Api/Admin/Public/Login/GetCaptchaImage")' height="34" />
                        </a>
                    </div>
                </div>
                <!--<div class="checkbox-custom">
        <input id="rememberMe" name="rememberMe" type="checkbox"> <label for="rememberMe">记住我</label>
    </div>-->
                <button class="btn btn-success btn-block" style="background:#1E9FFF;border:0px" onclick="loginForm(); return false;">登录</button>

                <div class="ui horizontal divider session-login__oauth-title">
                    <span class="text-muted">
                        其他方式登录
                    </span>
                </div>
                <div class="layui-form-item login-oauth-group text-center">
                    <a href="javascript:;" onclick="OtherLogin('qq'); return false;"><i class="layui-icon layui-icon-login-qq" style="color:#3492ed;"></i></a>
                    <a href="javascript:;" onclick="OtherLogin('wechat'); return false;"><i class="layui-icon layui-icon-login-wechat" style="color:#4daf29;"></i></a>
                    <a href="javascript:;" onclick="OtherLogin('weibo'); return false;"><i class="layui-icon layui-icon-login-weibo" style="color:#CF1900;"></i></a>
                </div>
            </form>
        </div>
    </div>
    <div class="login-footer" style="display:none">
        <div style="text-align:center">
            &copy; 2019-@DateTime.Now.Year <a href="http://cnbing.net" target="_blank" style="color:white">GeneralNetCore</a> All Rights Reserved. <br>
            <br>
        </div>
    </div>
</div>


<script src="/js/aes.js"></script>
<script type="text/javascript">
    $(function () {
        if ($.cookie('RememberMe') == 1) {
            $("#rememberMe").prop("checked", true);

        }
        $("#rememberMe").click(function () {
            if ($(this).prop("checked")) {
                $.cookie('RememberMe', 1, { expires: 30, path: '/' });
            }
        });

        $("#imgCaptchaCode").click(function () {
            $(this).attr("src", '@Url.Content("~/Api/Admin/Public/Login/GetCaptchaImage")' + '?t=' + new Date().getTime());
        });

        $("#form").validate({
            rules: {
                userName: { required: true },
                password: { required: true }
            }
        });

        $.validator.setDefaults({
            submitHandler: function () {
                loginForm();
            }
        });
    });

    function OtherLogin(parm) {
        if (parm == "wechat") {
            ys.ajax({
                url: '@Url.Content("~/Api/Admin/Public/Login/WeChatGenerateQRCode")',
                type: "post",
                data: {},
                success: function (obj) {
                    if (obj.code == 1) {
                        document.cookie = "WeChatUser_=" + obj.data + ";path=/;"; //设置cookie
                        layer.open({
                            type: 1
                            , title: false //不显示标题栏
                            , closeBtn: false
                            , area: '300px;'
                            , shade: 0.8
                            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                            , btn: ['关闭']
                            , btnAlign: 'c'
                            , moveType: 1 //拖拽模式，0或者1
                            , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;"><img src="' + obj.message + '" width="200px" height="200px" /><br><br>扫码请不要关闭此页面！</div>'
                            , success: function (layero, dIndex) {
                                var lt = setInterval(function () {
                                    $.post("/Api/Admin/Public/Login/WeChatRefreshStatus", {}, function (res2) {
                                        if (res2.code == 2) {
                                            clearInterval(lt);
                                            layer.close(dIndex);
                                            ys.msgError(res2.message);
                                        } else if (res2.code == 1) {
                                            clearInterval(lt);
                                            layer.close(dIndex);
                                            redirectToIndex();
                                        }
                                        //console.log(res2);
                                    }, "JSON");
                                }, 1000);


                                var btn = layero.find('.layui-layer-btn');

                                btn.find('.layui-layer-btn0').click(function () {
                                    layer.close(dIndex);
                                    clearInterval(lt);
                                })
                                //btn.find('.layui-layer-btn0').attr({
                                //    href: '/'
                                //    , target: '_blank'
                                //});
                            }
                        });
                    }
                    else {
                        ys.msgError(obj.message);
                    }
                }
            });

        } else if (parm == "qq") {
            ys.ajax({
                url: '@Url.Content("~/Api/Admin/Public/Login/QQAuthorize")',
                type: "post",
                data: {},
                success: function (obj) {
                    if (obj.code == 1) {
                        document.cookie = "QQUser_=" + obj.data + ";path=/;"; //设置cookie
                        //跳转授权地址
                        window.location.href = obj.message;
                    }
                    else {
                        ys.msgError(obj.message);
                    }
                }
            });
        }
    }


    function loginForm() {
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls();
            postData.Password = pwdEncryption(postData.Password);
            ys.ajax({
                url: '@Url.Content("~/Api/Admin/Public/Login/LoginProcess")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.code == 1) {
                        ys.msgSuccess(obj.message);
                        redirectToIndex();
                    }
                    else {
                        ys.msgError(obj.message);
                        changecode();
                    }
                }
            });
        }
    }

    function changecode() {
        $("#imgCaptchaCode").attr("src", "/Api/Admin/Public/Login/GetCaptchaImage?" + Math.random());
    }


    function redirectToIndex() {
        location.href = '@Url.Content("~/Admin/Index")';
    }
</script>